﻿using CJGL;
using Comm;
using Common;
using JShiwork.FrmUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Windows.Forms;

namespace Ztest
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            // Application.Run(new Form1());
            Mutex instance = new Mutex(true, "MutexName", out bool createdNew);
            if (createdNew)
            {

                string NTime = XML.read("NTime", "p.xml");
                DateTime xmlTime = Convert.ToDateTime(NTime);
                if (NTime != null && DateTime.Now < xmlTime)
                {
                    MessageBox.Show("请修改正确电脑的时间！");
                }
                else
                {
                    XML.write("NTime", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), "p.xml");
                    DateTime EndTime = new DateTime(2025, 12, 02);
                    string pass = XML.read("pass", "p.xml");
                    string dsds = ComputerInfo.GetHDDSerial().Trim();
                    dsds = ComputerInfo.GetEncryptPassword(dsds);
                    if (xmlTime < EndTime && (pass != dsds))
                    {
                        MessageBox.Show("当前软件试用期，到期时间" + EndTime.ToShortDateString());
                        Application.Run(new frmMain());
                    }
                    else
                    {
                        if (pass != dsds)
                        {
                            PassWord passfrom = new PassWord();
                            if (passfrom.ShowDialog() == DialogResult.OK)
                            {
                                Application.Run(new frmMain());
                            }
                        }
                        else
                        {
                            Application.Run(new frmMain());
                        }
                        instance.ReleaseMutex();
                    }
                }


            }
            else
            {
                MessageBox.Show("程序已经在启动中");
                Application.Exit();

            }
        }
    }
}
